"use strict";
(function(window, document) {
    document.domain = "fang.com";
    var DIF_dragging = false;
    var DIF_iframeBeingDragged = "";
    var DIF_iframeObjects = {};
    var DIF_iframeWindows = {};
    var DIF_iframeMouseDownLeft = {};
    var DIF_iframeMouseDownTop = {};
    var DIF_pageMouseDownLeft = {};
    var DIF_pageMouseDownTop = {};
    var DIF_handles = {};
    var DIF_highestZIndex = 99;
    var DIF_raiseSelectedIframe = false;
    var DIF_allowDragOffScreen = false;
    var mouseMoveListener = false;

    function addHandle(o, win) {
        if (!mouseMoveListener) {
            mouseMoveListener = true;
            win.$(document).on("mousemove", function(evt) {
                if (typeof evt === "undefined") { evt = event }
                DIF_mouseMove(evt, window)
            })
        }
        var name = DIF_getIframeId(win);
        if (DIF_handles[name] === undefined) {
            DIF_handles[name] = [];
            DIF_iframeMouseDownLeft[name] = 0;
            DIF_iframeMouseDownTop[name] = 0;
            DIF_pageMouseDownLeft[name] = 0;
            DIF_pageMouseDownTop[name] = 0
        }
        DIF_handles[name].push(o)
    }

    function DIF_getEventPosition(evt) {
        var pos = {};
        pos.x = 0;
        pos.y = 0;
        if (!evt) { evt = window.event }
        if (typeof evt.pageX === "number") {
            pos.x = evt.pageX;
            pos.y = evt.pageY
        } else {
            pos.x = evt.clientX;
            pos.y = evt.clientY;
            if (!top.opera) {
                if (!document.compatMode || document.compatMode === "BackCompat") {
                    var body = document.body;
                    pos.x += body.scrollLeft;
                    pos.y += body.scrollTop
                } else {
                    var ele = document.documentElement;
                    pos.x += ele.scrollLeft;
                    pos.y += ele.scrollTop
                }
            }
        }
        return pos
    }

    function DIF_getIframeId(win) {
        if (win.iframeId) { return win.iframeId }
        var iframes = document.getElementsByTagName("IFRAME");
        for (var i = 0; i < iframes.length; i++) {
            var o = iframes.item(i);
            var w = null;
            if (o.contentWindow) { w = o.contentWindow } else if (window.frames && window.frames[o.id].window) { w = window.frames[o.id] }
            if (w === win) {
                DIF_iframeWindows[o.id] = win;
                DIF_iframeObjects[o.id] = o;
                win.iframeId = o.id;
                return o.id
            }
        }
        return null
    }

    function DIF_getObjectXY(o) {
        var res = {};
        res.x = 0;
        res.y = 0;
        if (o) {
            res.x = o.offsetLeft;
            res.y = o.offsetTop
        }
        return res
    }

    function getSrcElement(e) { var tgt = e.target; while (tgt.nodeType !== 1) { tgt = tgt.parentNode } return tgt }

    function isHandleClicked(handle, objectClicked) {
        if (handle === objectClicked) { return true }
        while (objectClicked.parentNode !== null) {
            if (objectClicked === handle) { return true }
            objectClicked = objectClicked.parentNode
        }
        return false
    }

    function DIF_begindrag(e, win) {
        var iframename = DIF_getIframeId(win);
        if (!iframename) { return }
        if (!DIF_handles[iframename] || DIF_handles[iframename].length < 1) { return }
        var isHandle = false;
        var t = e.srcElement || getSrcElement(e);
        for (var i = 0; i < DIF_handles[iframename].length; i++) { if (isHandleClicked(DIF_handles[iframename][i], t)) { isHandle = true; break } }
        if (!isHandle) { return false }
        DIF_iframeBeingDragged = iframename;
        if (DIF_raiseSelectedIframe) { DIF_iframeObjects[DIF_iframeBeingDragged].style.zIndex = DIF_highestZIndex++ }
        DIF_dragging = true;
        var pos = DIF_getEventPosition(e);
        DIF_iframeMouseDownLeft[DIF_iframeBeingDragged] = pos.x;
        DIF_iframeMouseDownTop[DIF_iframeBeingDragged] = pos.y;
        var o = DIF_getObjectXY(DIF_iframeObjects[DIF_iframeBeingDragged]);
        DIF_pageMouseDownLeft[DIF_iframeBeingDragged] = o.x - 0 + pos.x;
        DIF_pageMouseDownTop[DIF_iframeBeingDragged] = o.y - 0 + pos.y
    }

    function DIF_enddrag(e) {
        var ele = DIF_iframeObjects[DIF_iframeBeingDragged];
        if (!ele) return;
        var o = DIF_getObjectXY(ele);
        var right = document.documentElement.clientWidth - (o.x + ele.offsetWidth);
        var bottom = document.documentElement.clientHeight - (o.y + ele.offsetHeight);
        var style = ele.style;
        style.right = Math.max(0, right) + "px";
        style.bottom = Math.max(0, bottom) + "px";
        style.left = "";
        style.top = "";
        DIF_dragging = false;
        DIF_iframeBeingDragged = ""
    }

    function DIF_mouseMove(e) { DIF_move(e, DIF_pageMouseDownLeft, DIF_pageMouseDownTop) }

    function DIF_iframemove(e) { DIF_move(e, DIF_iframeMouseDownLeft, DIF_iframeMouseDownTop) }

    function DIF_move(e, dx, dy) {
        if (DIF_dragging) {
            var pos = DIF_getEventPosition(e);
            DIF_drag(pos.x - dx[DIF_iframeBeingDragged], pos.y - dy[DIF_iframeBeingDragged])
        }
    }

    function DIF_drag(x, y) {
        var ele = DIF_iframeObjects[DIF_iframeBeingDragged];
        var o = DIF_getObjectXY(ele);
        var newPositionX = o.x - 0 + x;
        var newPositionY = o.y - 0 + y;
        if (!DIF_allowDragOffScreen) { if (newPositionX < 0) { newPositionX = 0 } if (newPositionY < 0) { newPositionY = 0 } }
        ele.style.left = newPositionX + "px";
        ele.style.top = newPositionY + "px";
        DIF_pageMouseDownLeft[DIF_iframeBeingDragged] += x;
        DIF_pageMouseDownTop[DIF_iframeBeingDragged] += y
    }
    window.DIF = {
        addHandle: addHandle,
        begindrag: DIF_begindrag,
        enddrag: DIF_enddrag,
        move: DIF_iframemove,
        dragend: function dragend(id) {
            DIF_iframeBeingDragged = id;
            DIF_enddrag()
        }
    }
})(window, document);
(function picView(window, document) {
    var _init = false;
    var tag_pic;
    var tag_img;
    var tag_video;
    var tag_close;
    var tag_prev;
    var tag_next;
    var _list;
    var _index;
    var initView = function initView() {
        var $ = window.webimxx.$;
        var url = "//static.soufunimg.com/upload/webim/im4/images/";
        var html = "<div class=\"view-pic\"style=\"display: none;position: fixed;top: 50%;left: 50%;z-index: 99999;overflow: hidden;width: 800px;height: 600px;margin: -300px 0 0 -400px;font-size: 0;line-height: 600px;text-align: center;background: rgba(0,0,0,.60);box-shadow: 0 1px 3px 0 rgba(0,0,0,.24);\" >" + "<img src=\"\"  style=\"display: none; max-width: 100%; max-height: 100%; vertical-align: middle;\"alt=\"\">" + "<video src=\"\"style=\"display: none; max-width: 100%; max-height: 100%; vertical-align: middle;\" controls=\"controls\"></video>" + "<a class=\"close\" href=\"javascript:;\" style=\"position: absolute; top: 0; right: 0; z-index: 9; width: 40px; height: 40px; background-color: rgba(0,0,0,.2); background-image: url(" + url + "close-white.png); background-repeat: no-repeat; background-position: center; background-size: 12px 12px; \" title=\"\u5173\u95ED\"></a>" + "<a class=\"prev\" href=\"javascript:;\" style=\"position: absolute; top: 50%; z-index: 9; width: 44px; height: 44px; margin-top: -24px; background-repeat: no-repeat; background-position: center; background-size: cover;left: 20px;" + " background-image: url(" + url + "prev.png); \" title=\"\"></a>" + "<a class=\"next\" href=\"javascript:;\" style=\"position: absolute; top: 50%; z-index: 9; width: 44px; height: 44px; margin-top: -24px; background-repeat: no-repeat; background-position: center; background-size: cover;right: 20px; background-image: url(" + url + "next.png); \"title=\"\"></a>" + "<a style=\"display:none;background-image: url(" + url + "prev-active.png);></a>" + "<a style=\"display:none;background-image: url(" + url + "next-active.png);></a></div>";
        tag_pic = $(html);
        $(document.body).append(tag_pic);
        tag_img = tag_pic.find("img");
        tag_video = tag_pic.find("video");
        tag_close = tag_pic.find(".close");
        tag_prev = tag_pic.find(".prev");
        tag_next = tag_pic.find(".next");
        tag_prev.mouseenter(function() { tag_prev.css("background-image", "url(" + url + "prev-active.png)") }).mouseleave(function() { tag_prev.css("background-image", "url(" + url + "prev.png)") }).click(function() {
            _index -= 1;
            window.openView(_list, _index)
        });
        tag_next.mouseenter(function() { tag_next.css("background-image", "url(" + url + "next-active.png)") }).mouseleave(function() { tag_next.css("background-image", "url(" + url + "next.png)") }).click(function() {
            _index += 1;
            window.openView(_list, _index)
        });
        tag_close.mouseenter(function() { tag_close.css("background-color", "#e01818") }).mouseleave(function() { tag_close.css("background-color", "rgba(0,0,0,.2)") }).click(function() {
            tag_pic.remove();
            _init = false
        });
        _init = true
    };
    window.openView = function(list, index) {
        if (!_init) { initView() }
        _list = list;
        _index = index;
        var item = list[index];
        if (item.command === "img") {
            tag_img[0].src = item.content;
            tag_video.hide();
            tag_img.show()
        } else {
            tag_video[0].src = item.content.split(";")[0];
            tag_img.hide();
            tag_video.show()
        }
        tag_prev.show();
        tag_next.show();
        if (index === 0) { tag_prev.hide() }
        if (index === list.length - 1) { tag_next.hide() }
        tag_pic.show()
    }
})(window, document);
(function requestJs(window, document) {
    var visibilityState;
    var eventType;
    if ("undefined" !== typeof document.hidden) {
        eventType = "visibilitychange";
        visibilityState = "visibilityState"
    } else if ("undefined" !== typeof document.mozHidden) {
        eventType = "mozvisibilitychange";
        visibilityState = "mozVisibilityState"
    } else if ("undefined" !== typeof document.msHidden) {
        eventType = "msvisibilitychange";
        visibilityState = "msVisibilityState"
    } else if ("undefined" !== typeof document.webkitHidden) {
        eventType = "webkitvisibilitychange";
        visibilityState = "webkitVisibilityState"
    }
    document.addEventListener && document.addEventListener(eventType, function() {
        if (document[visibilityState] === "visible") {
            var fangWebIM = window.webimxx.fangWebIM;
            fangWebIM && fangWebIM.checkUser && fangWebIM.checkUser();
            fangWebIM && fangWebIM.setChatRead && fangWebIM.setChatRead()
        }
    }, false);
    var isPC = false;
    var p = navigator.platform;
    var ua = navigator.userAgent;
    if (p.indexOf("Win") === 0 || p.indexOf("Mac") === 0 || p === "X11" || p.indexOf("Linux") === 0 && !(p.indexOf("Linux arm") !== -1 || p.indexOf("Linux aar") !== -1 || ua.indexOf("Android") !== -1)) { isPC = true }
    var webimFangWebIM;
    var contacts = [];
    var broker = [];
    var consultant = [];
    var customerService = [];
    var setBoxState = false;
    window.fangWebIM = { init: function init() {}, openChat: function openChat(data) { if (webimFangWebIM) { webimFangWebIM.openChat(data) } else { contacts = data } }, addBroker: function addBroker(data) { if (webimFangWebIM) { webimFangWebIM.addBroker(data) } else { broker = data } }, addConsultant: function addConsultant(data) { if (webimFangWebIM) { webimFangWebIM.addConsultant(data) } else { consultant = data } }, addCustomerService: function addCustomerService(data) { if (webimFangWebIM) { webimFangWebIM.addCustomerService(data) } else { customerService = data } }, open: function open() { setBoxState = true } };
    if (!isPC) return;
    var webimConfig = window.webimConfig || {};
    if (!webimConfig.type) { webimConfig.type = "webxf" }

    function createIframe() {
        var url = window.location.protocol === "http:" ? "http://chat.client.3g.fang.com/webim" : "https://chatclient.3g.fang.com/webim";
        var b = document.createElement("IFRAME");
        b.style.position = "fixed";
        b.style.right = 0;
        b.style.bottom = "0";
        b.style.zIndex = 99999;
        b.src = url;
        b.id = "webimIframe";
        b.frameBorder = 0;
        b.scrolling = "no";
        b.width = 2;
        b.height = 20;
        b.name = "webimxx";
        document.body.appendChild(b);
        return b
    }
    var frame = createIframe();
    var resize = function resize(config) {
        frame.style.height = config.height;
        frame.style.width = config.width
    };
    var animate = function animate(obj, json, interval, sp, fn) {
        clearInterval(obj.timer);

        function getStyle(obj, arr) { if (obj.currentStyle) { return obj.currentStyle[arr] } return document.defaultView.getComputedStyle(obj, null)[arr] }
        obj.timer = setInterval(function() {
            var flag = true;
            for (var arr in json) {
                if (json.hasOwnProperty(arr)) {
                    var icur = 0;
                    if (arr === "opacity") { icur = Math.round(parseFloat(getStyle(obj, arr)) * 100) } else { icur = parseInt(getStyle(obj, arr)) }
                    var speed = (json[arr] - icur) * sp;
                    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
                    if (icur !== json[arr]) { flag = false }
                    if (arr === "opacity") {
                        obj.style.filter = "alpha(opacity : '+(icur + speed)+' )";
                        obj.style.opacity = (icur + speed) / 100
                    } else { obj.style[arr] = icur + speed + "px" }
                }
            }
            if (flag) { clearInterval(obj.timer); if (fn) { fn() } }
        }, interval)
    };

    function setFramewh(config) { var noanimate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; try { if (noanimate) { resize(config) } else { animate(frame, { width: parseInt(config.width), height: parseInt(config.height) }, 10, 0.1) } } catch (e) { resize(config) } }
    var foo = function foo() {
        var webim = window.webimxx;
        var fangWebIM = webim.fangWebIM;
        if (fangWebIM) {
            webimFangWebIM = fangWebIM;
            fangWebIM.setdata && fangWebIM.setdata(webimConfig);
            while (contacts.length > 0) { fangWebIM.openChat(contacts.shift()) }
            if (broker.length > 0) { fangWebIM.addBroker(broker) }
            if (consultant.length > 0) { fangWebIM.addConsultant(consultant) }
            if (customerService.length > 0) { fangWebIM.addCustomerService(customerService) }
            if (setBoxState === true) { fangWebIM.open() }
        } else { setTimeout(function() { foo() }, 1000) }
    };
    frame.onload = foo;
    window.setFramewh = setFramewh
})(window, document);